home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / spiders.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  5KB  |  190 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "machine/6821pia.h"
  12. #include "cpu/m6809/m6809.h"
  13.  
  14.  
  15.  
  16. /* Declare inividual irq handlers, may be able to combine later */
  17. /* Main CPU */
  18. void spiders_irq0a(int state) { cpu_set_irq_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
  19. void spiders_irq0b(int state) { cpu_set_irq_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
  20. void spiders_irq1a(int state) { cpu_set_irq_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
  21. void spiders_irq1b(int state) { cpu_set_irq_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
  22. void spiders_irq2a(int state) { cpu_set_irq_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
  23. void spiders_irq2b(int state) { cpu_set_irq_line(0,M6809_IRQ_LINE,state ? ASSERT_LINE : CLEAR_LINE); }
  24.  
  25. /* Sound CPU */
  26. void spiders_irq3a(int state) { }
  27. void spiders_irq3b(int state) { }
  28.  
  29. /* Function prototypes */
  30.  
  31. WRITE_HANDLER( spiders_flip_w );
  32. WRITE_HANDLER( spiders_vrif_w );
  33. READ_HANDLER( spiders_vrom_r );
  34.  
  35.  
  36. /* Declare PIA structure */
  37.  
  38. /* PIA 0, main CPU */
  39. static struct pia6821_interface pia_0_intf =
  40. {
  41.     /*inputs : A/B,CA/B1,CA/B2 */ input_port_0_r, input_port_1_r, 0, 0, 0, 0,
  42.     /*outputs: A/B,CA/B2       */ 0, 0, 0, 0,
  43.     /*irqs   : A/B             */ spiders_irq0a, spiders_irq0b
  44. };
  45.  
  46. /* PIA 1, main CPU */
  47. static struct pia6821_interface pia_1_intf =
  48. {
  49.     /*inputs : A/B,CA/B1,CA/B2 */ spiders_vrom_r, 0, input_port_5_r, 0, 0, 0,
  50.     /*outputs: A/B,CA/B2       */ 0, spiders_vrif_w, 0, spiders_flip_w,
  51.     /*irqs   : A/B             */ spiders_irq1a, spiders_irq1b
  52. };
  53.  
  54. /* PIA 2, main CPU */
  55. static struct pia6821_interface pia_2_intf =
  56. {
  57.     /*inputs : A/B,CA/B1,CA/B2 */ 0, 0, 0, 0, 0, 0,
  58.     /*outputs: A/B,CA/B2       */ 0, 0, 0, 0,
  59.     /*irqs   : A/B             */ spiders_irq2a, spiders_irq2b
  60. };
  61.  
  62. /* PIA 3, sound CPU */
  63. static struct pia6821_interface pia_3_intf =
  64. {
  65.     /*inputs : A/B,CA/B1,CA/B2 */ 0, 0, 0, 0, 0, 0,
  66.     /*outputs: A/B,CA/B2       */ 0, 0, 0, 0,
  67.     /*irqs   : A/B             */ spiders_irq3a, spiders_irq3b
  68. };
  69.  
  70.  
  71. /***************************************************************************
  72.  
  73.     Spiders Machine initialisation
  74.  
  75. ***************************************************************************/
  76.  
  77. void spiders_init_machine(void)
  78. {
  79.     pia_unconfig();
  80.     pia_config(0, PIA_STANDARD_ORDERING  | PIA_8BIT, &pia_0_intf);
  81.     pia_config(1, PIA_ALTERNATE_ORDERING | PIA_8BIT, &pia_1_intf);
  82.     pia_config(2, PIA_STANDARD_ORDERING  | PIA_8BIT, &pia_2_intf);
  83.     pia_config(3, PIA_STANDARD_ORDERING  | PIA_8BIT, &pia_3_intf);
  84.     pia_reset();
  85. }
  86.  
  87.  
  88.  
  89. /***************************************************************************
  90.  
  91.     Timed interrupt handler - Updated PIA input ports
  92.  
  93. ***************************************************************************/
  94.  
  95. int spiders_timed_irq(void)
  96. {
  97.     /* Update CA1 on PIA1 - copy of PA0 (COIN1?) */
  98.     pia_0_ca1_w(0 , input_port_0_r(0)&0x01);
  99.  
  100.     /* Update CA2 on PIA1 - copy of PA0 (PS2) */
  101.     pia_0_ca2_w(0 , input_port_0_r(0)&0x02);
  102.  
  103.     /* Update CA1 on PIA1 - copy of PA0 (COIN1?) */
  104.     pia_0_cb1_w(0 , input_port_6_r(0));
  105.  
  106.     /* Update CB2 on PIA1 - NOT CONNECTED */
  107.  
  108.     return ignore_interrupt();
  109. }
  110.  
  111.  
  112. /***************************************************************************
  113.  
  114.     Video access port definition (On PIA 2)
  115.  
  116.     Bit 7 6 5 4 3 2 1 0
  117.         X                Mode Setup/Read 1/0
  118.             X X          Latch select (see below)
  119.                 X X X X  Data nibble
  120.  
  121.     When in setup mode data is clocked into the latch by a read from port a.
  122.     When in read mode the read from port a auto increments the address.
  123.  
  124.     Latch 0 - Low byte low nibble
  125.           1 - Low byte high nibble
  126.           2 - High order low nibble
  127.           3 - High order high nibble
  128.  
  129. ***************************************************************************/
  130.  
  131. static int vrom_address;
  132. static int vrom_ctrl_mode;
  133. static int vrom_ctrl_latch;
  134. static int vrom_ctrl_data;
  135.  
  136. int spiders_video_flip=0;
  137.  
  138. WRITE_HANDLER( spiders_flip_w )
  139. {
  140.     spiders_video_flip=data;
  141. }
  142.  
  143. WRITE_HANDLER( spiders_vrif_w )
  144. {
  145.     vrom_ctrl_mode=(data&0x80)>>7;
  146.     vrom_ctrl_latch=(data&0x30)>>4;
  147.     vrom_ctrl_data=15-(data&0x0f);
  148. }
  149.  
  150. READ_HANDLER( spiders_vrom_r )
  151. {
  152.     int retval;
  153.     unsigned char *RAM = memory_region(REGION_GFX1);
  154.  
  155.     if(vrom_ctrl_mode)
  156.     {
  157.         retval=RAM[vrom_address];
  158. //            logerror("VIDEO : Read data %02x from Port address %04x\n",retval,vrom_address);
  159.         vrom_address++;
  160.     }
  161.     else
  162.     {
  163.         switch(vrom_ctrl_latch)
  164.         {
  165.             case 0:
  166.                 vrom_address&=0xfff0;
  167.                 vrom_address|=vrom_ctrl_data;
  168.                 break;
  169.             case 1:
  170.                 vrom_address&=0xff0f;
  171.                 vrom_address|=vrom_ctrl_data<<4;
  172.                 break;
  173.             case 2:
  174.                 vrom_address&=0xf0ff;
  175.                 vrom_address|=vrom_ctrl_data<<8;
  176.                 break;
  177.             case 3:
  178.                 vrom_address&=0x0fff;
  179.                 vrom_address|=vrom_ctrl_data<<12;
  180.                 break;
  181.             default:
  182.                 break;
  183.         }
  184.         retval=0;
  185. //            logerror("VIDEO : Port address set to %04x\n",vrom_address);
  186.     }
  187.     return retval;
  188. }
  189.  
  190.